/* GUI CONVERTED from sosorp09.p (converter v1.76) Wed Jul 10 23:13:50 2002 */
/* sosorp09.p - SALES SHIPPING REPORT BY CUSTOMER                       */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.10.2.8 $                                                */
/*K0L8         */
/*V8:ConvertMode=FullGUIReport                                 */
/* REVISION: 1.0      LAST MODIFIED: 04/27/87   BY: PML      */
/* REVISION: 2.1      LAST MODIFIED: 01/19/88   BY: RL  *A153**/
/* REVISION: 4.0      LAST MODIFIED: 03/31/88   BY: FLM *A175**/
/* REVISION: 4.0      LAST MODIFIED: 10/13/88   BY: flm *A482**/
/* REVISION: 5.0      LAST MODIFIED: 01/24/89   BY: MLB *A619**/
/* REVISION: 5.0      LAST MODIFIED: 02/08/89   BY: JLC *C0028*/
/* REVISION: 5.0      LAST MODIFIED: 03/20/89   BY: MLB *B072**/
/* REVISION: 5.0      LAST MODIFIED: 07/05/89   BY: BJJ *B106* */
/* REVISION: 6.0      LAST MODIFIED: 04/05/90   BY: pml *D001* */
/* REVISION: 6.0      LAST MODIFIED: 03/06/91   BY: afs *D408**/
/* REVISION: 6.0      LAST MODIFIED: 10/21/91   BY: afs *D903**/
/* REVISION: 7.3      LAST MODIFIED: 11/19/92   BY: jcd *G348**/
/* REVISION: 7.3      LAST MODIFIED: 03/09/93   BY: tjs *G791**/
/* REVISION: 7.3      LAST MODIFIED: 11/06/94   BY: dpm *FT42**/
/* REVISION: 7.3      LAST MODIFIED: 05/11/95   BY: jym *F0RM**/
/* REVISION: 7.3      LAST MODIFIED: 04/10/96   BY: jzw *G1P6**/
/* REVISION: 8.6      LAST MODIFIED: 10/04/97   BY: ckm *K0L8**/
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane     */
/* REVISION: 8.6E     LAST MODIFIED: 03/11/98   BY: *J2G1* Niranjan R.   */
/* REVISION: 8.6E     LAST MODIFIED: 07/05/98   BY: *L024* Sami Kureishy */
/* REVISION: 9.1      LAST MODIFIED: 10/28/99   BY: *N04Y* Surekha Joshi */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 06/29/00   BY: *N0DX* BalbeerS Rajput  */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KN* myb              */
/* REVISION: 9.1      LAST MODIFIED: 10/13/00   BY: *N0WC* Mudit Mehta      */
/* Old ECO marker removed, but no ECO header exists *B388*                    */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.10.2.7      BY: Ellen Borden      DATE: 03/13/02  ECO: *P00G*  */
/* $Revision: 1.10.2.8 $     BY: Hareesh V.        DATE: 06/21/02  ECO: *N1HY*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* DISPLAY TITLE */

/*GUI global preprocessor directive settings */
&GLOBAL-DEFINE PP_PGM_RP TRUE
&GLOBAL-DEFINE PP_ENV_GUI TRUE


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "2+ "}
{cxcustom.i "SOSORP09.P"}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE sosorp09_p_1 "Unit Price"
/* MaxLen: Comment: */

&SCOPED-DEFINE sosorp09_p_2 "Summary/Detail"
/* MaxLen: Comment: */

&SCOPED-DEFINE sosorp09_p_4 "Qty Shipped"
/* MaxLen: Comment: */

&SCOPED-DEFINE sosorp09_p_5 "Show Gr Margin"
/* MaxLen: Comment: */

&SCOPED-DEFINE sosorp09_p_6 "Ext Margin"
/* MaxLen: Comment: */

&SCOPED-DEFINE sosorp09_p_7 "Ext Price"
/* MaxLen: Comment: */

&SCOPED-DEFINE sosorp09_p_10 "%Margin"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define variable addr like tr_addr.
define variable addr1 like tr_addr.
define variable so_job like tr_so_job.
define variable so_job1 like tr_so_job.
define variable part like tr_part.
define variable part1 like tr_part.
define variable trdate like tr_effdate.
define variable trdate1 like tr_effdate.
define variable region like cm_region.
define variable region1 like cm_region.
define variable name like ad_name.
define variable ext_price like tr_price label {&sosorp09_p_7}
   format "->,>>>,>>>,>>9.99".
define variable gr_margin like tr_price.
define variable ext_gr_margin like tr_price label {&sosorp09_p_6}
   format "->,>>>,>>>,>>9.99<<<".
define variable summary like mfc_logical format {&sosorp09_p_2}
   label {&sosorp09_p_2}.
define variable base_rpt like so_curr.

define variable base_price like tr_price.
define variable disp_curr as character format "x(1)" label "C".
define variable prod_line like tr_prod_line.
define variable prod_line1 like tr_prod_line.
define variable pct_margin as decimal format "->>9.99"
   label {&sosorp09_p_10}.
define variable show_margin like mfc_logical initial yes label {&sosorp09_p_5}.
define variable unit_cost like tr_mtl_std.
define variable mc-error-number like msg_nbr no-undo.

{gprunpdf.i "mcpl" "p"}

/* CONSIGNMENT VARIABLES */
define variable consign_qty_ship like tr_qty_loc.
{socnvars.i}




/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
addr           colon 15
   addr1          label {t001.i} colon 49 skip
   part           colon 15
   part1          label {t001.i} colon 49 skip

   prod_line      colon 15
   prod_line1     label {t001.i} colon 49 skip
   trdate         colon 15
   trdate1        label {t001.i} colon 49 skip
   so_job         colon 15
   so_job1        label {t001.i} colon 49 skip
   region         colon 15
   region1        label {t001.i} colon 49 skip(1)
   show_margin    colon 15 skip
   summary        colon 15 skip
   base_rpt       colon 15 skip
 SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER.
 F-a-title = &IF (DEFINED(SELECTION_CRITERIA) = 0)
  &THEN " Selection Criteria "
  &ELSE {&SELECTION_CRITERIA}
  &ENDIF .
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame a =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame a + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5. /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

{wbrp01.i}

/* DETERMINE IF CUSTOMER CONSIGNMENT IS ACTIVE */
{gprun.i ""gpmfc01.p""
   "(input ENABLE_CUSTOMER_CONSIGNMENT,
     input 10,
     input ADG,
     input CUST_CONSIGN_CTRL_TABLE,
     output using_cust_consignment)"}


/*GUI*/ {mfguirpa.i true "printer" 132 " " " " " "  }

/*GUI repeat : */
/*GUI*/ procedure p-enable-ui:

   if part1 = hi_char then part1 = "".
   if addr1 = hi_char then addr1 = "".
   if so_job1 = hi_char then so_job1 = "".
   if trdate = low_date then trdate = ?.
   if trdate1 = hi_date then trdate1 = ?.
   if prod_line1 = hi_char then prod_line1 = "".
   if region1 = hi_char then region1 = "".

   if c-application-mode <> 'web' then
   
run p-action-fields (input "display").
run p-action-fields (input "enable").
end procedure. /* p-enable-ui, replacement of Data-Entry GUI*/

/*GUI*/ procedure p-report-quote:


   {wbrp06.i &command = update &fields = "  addr addr1 part part1 prod_line
        prod_line1 trdate trdate1 so_job so_job1 region region1 show_margin summary base_rpt" &frm = "a"}

   if (c-application-mode <> 'web') or
      (c-application-mode = 'web' and
      (c-web-request begins 'data')) then do:

      bcdparm = "".
      {mfquoter.i addr       }
      {mfquoter.i addr1      }
      {mfquoter.i part       }
      {mfquoter.i part1      }
      {mfquoter.i prod_line  }
      {mfquoter.i prod_line1 }
      {mfquoter.i trdate     }
      {mfquoter.i trdate1    }
      {mfquoter.i so_job     }
      {mfquoter.i so_job1    }
      {mfquoter.i region     }
      {mfquoter.i region1    }
      {mfquoter.i show_margin}
      {mfquoter.i summary    }
      {mfquoter.i base_rpt   }

      if part1 = "" then part1 = hi_char.
      if prod_line1 = "" then prod_line1 = hi_char.
      if addr1 = "" then addr1 = hi_char.
      if trdate = ? then trdate = low_date.
      if trdate1 = ? then trdate1 = hi_date.
      if so_job1 = "" then so_job1 = hi_char.
      if region1 = "" then region1 = hi_char.

   end.

   /* OUTPUT DESTINATION SELECTION */
   
/*GUI*/ end procedure. /* p-report-quote */
/*GUI - Field Trigger Section */

/*GUI MFSELxxx removed*/
/*GUI*/ procedure p-report:
/*GUI*/   {gpprtrpa.i "printer" 132 " " " " " " " " }
/*GUI*/   mainloop: do on error undo, return error on endkey undo, return error:

define buffer rcttrans for tr_hist.


    {hksimsg.i """" """"}

   {mfphead.i}

   FORM /*GUI*/ 
      skip(1)
   with STREAM-IO /*GUI*/  frame a1 page-top width 132.
   view frame a1.

   {&SOSORP09-P-TAG1}
   for each cm_mstr where
         (cm_addr >= addr and cm_addr <= addr1) and
         (cm_region >= region and cm_region <= region1)

         use-index cm_sort no-lock,
         each tr_hist where (tr_addr = cm_addr) and
         (tr_part >= part and tr_part <= part1)
         and (tr_prod_line >= prod_line and tr_prod_line <= prod_line1)
         and (tr_effdate >= trdate and tr_effdate <= trdate1)
         and (tr_so_job >= so_job and tr_so_job <= so_job1)
         and (tr_type = "ISS-SO"   or tr_type = "RCT-SOR" or
              tr_type = "CN-SHIP" OR tr_type = "ISS-CSR")   /*added by fdn*/
       AND (LOOKUP(tr_site,GLOBAL_user_site) > 0)

         and ((base_rpt = "")
         or (tr_curr = base_rpt))
         use-index tr_addr_eff  no-lock
         break by cm_sort by tr_addr
         by tr_part by tr_effdate
      with frame b width 132 no-box:
      {&SOSORP09-P-TAG2}
      /* SET EXTERNAL LABELS */
      setFrameLabels(frame b:handle).
      
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/


      if using_cust_consignment then do:
         assign
          consign_flag = no
          consign_qty_ship = 0.
         {gprunmo.i
            &program = "socnsod1.p"
            &module = "ACN"
            &param = """(input tr_nbr,
                         input tr_line,
                         output consign_flag,
                         output consign_loc,
                         output intrans_loc,
                         output max_aging_days,
                         output auto_replenish)"""}

         if consign_flag and (tr_type = "ISS-SO" OR tr_type = "ISS-CSR") then   /*added by fdn*/
            next.

         for first rcttrans where
             rcttrans.tr_trnbr = integer(tr_hist.tr_rmks)
             no-lock:
                consign_qty_ship = rcttrans.tr_qty_loc.
         end.  /* for first rcttrans */

      end.  /* if using_cust_consignment */

      if first-of(tr_addr) and not summary then do:
         if page-size - line-counter < 3 then page.
         if not summary then display with frame b STREAM-IO /*GUI*/ .
         else display with frame c STREAM-IO /*GUI*/ .

         put {gplblfmt.i
            &FUNC=getTermLabel(""CUSTOMER"",8)
            &CONCAT="': '"
            } tr_addr " " cm_sort.
      end.

      base_price = tr_price.
      disp_curr = "".

      if base_rpt <> ""
         and tr_curr <> base_curr then

      do:
         {gprunp.i "mcpl" "p" "mc-curr-conv"
            "(input base_curr,
              input tr_curr,
              input tr_ex_rate2,
              input tr_ex_rate,
              input base_price,
              input false,
              output base_price,
              output mc-error-number)"}.

         if mc-error-number <> 0 then do:
            {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
         end.
      end. /* IF BASE_RPT <> "" */

      if base_rpt = ""
         and tr_curr <> base_curr
         then
            disp_curr = getTermLabel("YES",1).
      ext_price =  - tr_qty_loc * base_price.

      unit_cost = - tr_gl_amt / tr_qty_loc.

      if consign_flag then
         assign
           ext_price =  consign_qty_ship * base_price
           unit_cost =  tr_gl_amt / consign_qty_ship.

      if tr_ship_type <> " " then do:
         unit_cost = tr_mtl_std + tr_lbr_std + tr_bdn_std
         + tr_ovh_std + tr_sub_std .
      end.

      gr_margin = tr_price - unit_cost.

      if base_rpt <> ""
         and tr_curr <> base_curr then
   do:

         {gprunp.i "mcpl" "p" "mc-curr-conv"
            "(input base_curr,
              input tr_curr,
              input tr_ex_rate2,
              input tr_ex_rate,
              input gr_margin,
              input false,
              output gr_margin,
              output mc-error-number)"}.
         if mc-error-number <> 0 then do:
            {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
         end.
      end. /* IF BASE_RPT <> "" */

      ext_gr_margin = - tr_qty_loc * gr_margin.

      if consign_flag then
         ext_gr_margin =  consign_qty_ship * gr_margin.

      if unit_cost = 0 then pct_margin = 100.
      else if (- tr_qty_loc) = 0 then pct_margin = 0.
      else pct_margin = (ext_gr_margin / ext_price) * 100.

      accumulate ext_gr_margin (total by  tr_addr by tr_part).
      accumulate tr_qty_loc (total  by tr_addr  by tr_part).
      accumulate ext_price (total  by tr_addr by tr_part).
      accumulate consign_qty_ship (total by tr_addr by tr_part).

      if consign_flag then do:
         if unit_cost = 0 then pct_margin = 100.
         else
           if consign_qty_ship = 0 then pct_margin = 0.
           else
             if ext_price = 0 then pct_margin = 0.
             else
                pct_margin = (ext_gr_margin / ext_price) * 100.
      end.  /* if consign_flag */

      find pt_mstr where pt_part = tr_part no-lock no-wait no-error.

      if not summary then do:

         if page-size - line-counter < 3 then page.

         display tr_trnbr tr_effdate  tr_part WITH STREAM-IO /*GUI*/ .
         if available pt_mstr then display pt_desc1 format "X(20)" WITH STREAM-IO /*GUI*/ .
            display
               (- tr_qty_loc) when (not consign_flag)
                         @ tr_qty_loc label {&sosorp09_p_4}
               consign_qty_ship when (consign_flag)
                         @ tr_qty_loc label {&sosorp09_p_4}
            disp_curr base_price label {&sosorp09_p_1} ext_price WITH STREAM-IO /*GUI*/ .
         if show_margin = yes then
         display
            ext_gr_margin pct_margin WITH STREAM-IO /*GUI*/ .
         if available pt_mstr and pt_desc2 <> "" then do:
            down 1.
            display pt_desc2 @ pt_desc1 WITH STREAM-IO /*GUI*/ .
         end.

         if last-of(tr_addr)  then do:
            if page-size - line-counter < 2 then page.
            underline tr_qty_loc ext_price.
            if show_margin = yes then
            underline
               ext_gr_margin
               pct_margin.

            display  getTermLabel("CUSTOMER_TOTAL",19) + ":" @ pt_desc1
               (- accum total by tr_addr (tr_qty_loc) )
                + accum total by tr_addr (consign_qty_ship)
              @ tr_qty_loc
               accum total by tr_addr (ext_price) @ ext_price WITH STREAM-IO /*GUI*/ .
            if show_margin = yes then
            display
               accum total by tr_addr (ext_gr_margin) @ ext_gr_margin
               (((accum total by tr_addr  (ext_gr_margin)) /
               (accum total by tr_addr (ext_price))) * 100) @ pct_margin WITH STREAM-IO /*GUI*/ .
         end.

         if last(tr_addr)  then do:
            if page-size - line-counter < 2 then page.
            underline tr_qty_loc ext_price.
            if show_margin = yes then
            underline
               ext_gr_margin pct_margin.

            display  getTermLabel("REPORT_TOTAL",19) + ":" @ pt_desc1
               (- accum total (tr_qty_loc) )
                + accum total (consign_qty_ship)
                  @ tr_qty_loc
               accum total  (ext_price) @ ext_price WITH STREAM-IO /*GUI*/ .
            if show_margin = yes then
            display
               accum total  (ext_gr_margin) @ ext_gr_margin
               (((accum total (ext_gr_margin)) /
               (accum total (ext_price))) * 100) @ pct_margin WITH STREAM-IO /*GUI*/ .
         end.
      end.  /* not summary */

      if summary then do:
         /* SET EXTERNAL LABELS */
         setFrameLabels(frame c:handle).
         if last-of(tr_addr)  then do:
            if page-size - line-counter < 2 then page.
            display tr_addr cm_sort cm_region
               accum total by tr_addr (ext_price) @ ext_price with
               frame c down width 132 STREAM-IO /*GUI*/ .

            if show_margin = yes then
            display
               accum total by tr_addr (ext_gr_margin) @ ext_gr_margin
               (((accum total by tr_addr (ext_gr_margin)) /
               (accum total by tr_addr (ext_price))) * 100) @ pct_margin
            with frame c down width 132 STREAM-IO /*GUI*/ .
         end.

         if last(tr_addr)  then do:
            if page-size - line-counter < 2 then page.
            underline ext_price with frame c.
            if show_margin = yes then
            underline
               ext_gr_margin pct_margin with frame c.

            display getTermLabel("REPORT_TOTAL",27) + ":" @ cm_sort
               accum total  (ext_price) @ ext_price with frame c STREAM-IO /*GUI*/ .
            if show_margin = yes then
            display
               accum total  (ext_gr_margin) @ ext_gr_margin
               (((accum total (ext_gr_margin)) /
               (accum total (ext_price))) * 100) @ pct_margin
            with frame c STREAM-IO /*GUI*/ .
         end.
      end. /* summary*/
   end. /*for each*/
   /* REPORT TRAILER  */
   
/*GUI*/ {mfguitrl.i} /*Replace mfrtrail*/

/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/

end.

{wbrp04.i &frame-spec = a}

/*GUI*/ end procedure. /*p-report*/
/*GUI*/ {mfguirpb.i &flds=" addr addr1 part part1 prod_line prod_line1 trdate trdate1 so_job so_job1 region region1 show_margin summary base_rpt "} /*Drive the Report*/
